%% Fidrmuc J., Kapounek, S., Ku�erov�, Z: Time�Frequency Analysis of Cryptocurrency Attention
% wavelet coherency: cryptocurrencies x SVI

%% Figure 03a - coherency: SVI vs. returns - bitcoin
close all
clear
clc
cd('... path ...')
load('data02.mat')
% transformation and variable definition
n=size(btc,2)/3;
m=length(btc_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(btc{:,j},1);
    names(:,i)=btcnames(:,j);
    j=j+3;
end
datelabel=btc_datelabel(2:end,:);
Y(:,1)=g_btc_bitfinex;
Y(:,2)=g_btc_bitstamp;
Y(:,3)=g_btc_bittrex;
Y(:,4)=g_btc_coinbase;
Y(:,5)=g_btc_kraken;
Y=diff(Y,1,1);
clearvars -except X Y datelabel names 
cname='bitcoin';
Cname='Bitcoin';

% NaN values
A1=[Y(:,1) X(:,1)];
A2=[Y(:,2) X(:,2)];
A3=[Y(:,3) X(:,3)];
A4=[Y(:,4) X(:,4)];
A5=[Y(:,5) X(:,5)];
B1=A1(~any(isnan(A1),2),:);datelabel1=datelabel(~any(isnan(A1),2),:);
B2=A2(~any(isnan(A2),2),:);datelabel2=datelabel(~any(isnan(A2),2),:);
B3=A3(~any(isnan(A3),2),:);datelabel3=datelabel(~any(isnan(A3),2),:);
B4=A4(~any(isnan(A4),2),:);datelabel4=datelabel(~any(isnan(A4),2),:);
B5=A5(~any(isnan(A5),2),:);datelabel5=datelabel(~any(isnan(A5),2),:);
clear datelabel X Y A*

% period definition
period1=(1:1:(length(datelabel1)))';
period2=(1:1:(length(datelabel2)))';
period3=(1:1:(length(datelabel3)))';
period4=(1:1:(length(datelabel4)))';
period5=(1:1:(length(datelabel5)))';

% ticks
ticks1=250:700:length(period1);
ticks2=250:720:length(period2);
ticks3=200:590:length(period3);
ticks4=270:710:length(period4);
ticks5=310:890:length(period5);

% figure creation
close all
figure('units','pixels','Position',[50,100,1500,300]);
s1=subplot(1,5,1);
wtc([period1 B1(:,1)],[period1 B1(:,2)],'maxscale',800)
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['SVI diff ("' cname ' ' cell2mat(names(1)) '")']});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=datelabel1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);

s2=subplot(1,5,2);
wtc([period2 B2(:,1)],[period2 B2(:,2)],'maxscale',800)
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(2)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wtc([period3 B3(:,1)],[period3 B3(:,2)],'maxscale',800)
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(3)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wtc([period4 B4(:,1)],[period4 B4(:,2)],'maxscale',800)
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(4)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wtc([period5 B5(:,1)],[period5 B5(:,2)],'maxscale',800)
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(5)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig03a','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'fig03a','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% Figure 03b - coherency: SVI vs. returns - ethereum
close all
clear
clc
cd('... path ...')
load('data02.mat')
% transformation and variable definition
n=size(eth,2)/3;
m=length(eth_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(eth{:,j},1);
    names(:,i)=ethnames(:,j);
    j=j+3;
end
datelabel=eth_datelabel(2:end,:);
Y(:,1)=g_eth_bitfinex;
Y(:,2)=g_eth_bitstamp;
Y(:,3)=g_eth_bittrex;
Y(:,4)=g_eth_coinbase;
Y(:,5)=g_eth_kraken;
Y=diff(Y,1,1);
clearvars -except X Y datelabel names 
cname='ethereum';
Cname='Ethereum';

% NaN values
A1=[Y(:,1) X(:,1)];
A2=[Y(:,2) X(:,2)];
A3=[Y(:,3) X(:,3)];
A4=[Y(:,4) X(:,4)];
A5=[Y(:,5) X(:,5)];
B1=A1(~any(isnan(A1),2),:);datelabel1=datelabel(~any(isnan(A1),2),:);
B2=A2(~any(isnan(A2),2),:);datelabel2=datelabel(~any(isnan(A2),2),:);
B3=A3(~any(isnan(A3),2),:);datelabel3=datelabel(~any(isnan(A3),2),:);
B4=A4(~any(isnan(A4),2),:);datelabel4=datelabel(~any(isnan(A4),2),:);
B5=A5(~any(isnan(A5),2),:);datelabel5=datelabel(~any(isnan(A5),2),:);
clear datelabel X Y A*

% period definition
period1=(1:1:(length(datelabel1)))';
period2=(1:1:(length(datelabel2)))';
period3=(1:1:(length(datelabel3)))';
period4=(1:1:(length(datelabel4)))';
period5=(1:1:(length(datelabel5)))';

% ticks
ticks1=200:520:length(period1);
ticks2=120:320:length(period2);
ticks3=150:390:length(period3);
ticks4=200:500:length(period4);
ticks5=250:610:length(period5);

% figure creation
close all
figure('units','pixels','Position',[50,100,1500,300]);
s1=subplot(1,5,1);
wtc([period1 B1(:,1)],[period1 B1(:,2)],'maxscale',800)
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['SVI diff ("' cname ' ' cell2mat(names(1)) '")']});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=datelabel1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);

s2=subplot(1,5,2);
wtc([period2 B2(:,1)],[period2 B2(:,2)],'maxscale',800)
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(2)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wtc([period3 B3(:,1)],[period3 B3(:,2)],'maxscale',800)
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(3)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wtc([period4 B4(:,1)],[period4 B4(:,2)],'maxscale',800)
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(4)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wtc([period5 B5(:,1)],[period5 B5(:,2)],'maxscale',800)
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(5)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig03b','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'fig03b','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% Figure 03c - coherency: SVI vs. returns - litecoin
close all
clear
clc
cd('... path ...')
load('data02.mat')
% transformation and variable definition
n=size(ltc,2)/3;
m=length(ltc_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(ltc{:,j},1);
    names(:,i)=ltcnames(:,j);
    j=j+3;
end
datelabel=ltc_datelabel(2:end,:);
Y(:,1)=g_ltc_bitfinex;
Y(:,2)=g_ltc_bitstamp;
Y(:,3)=g_ltc_bittrex;
Y(:,4)=g_ltc_coinbase;
Y(:,5)=g_ltc_kraken;
Y=diff(Y,1,1);
clearvars -except X Y datelabel names 
cname='litecoin';
Cname='Litecoin';

% NaN values
A1=[Y(:,1) X(:,1)];
A2=[Y(:,2) X(:,2)];
A3=[Y(:,3) X(:,3)];
A4=[Y(:,4) X(:,4)];
A5=[Y(:,5) X(:,5)];
B1=A1(~any(isnan(A1),2),:);datelabel1=datelabel(~any(isnan(A1),2),:);
B2=A2(~any(isnan(A2),2),:);datelabel2=datelabel(~any(isnan(A2),2),:);
B3=A3(~any(isnan(A3),2),:);datelabel3=datelabel(~any(isnan(A3),2),:);
B4=A4(~any(isnan(A4),2),:);datelabel4=datelabel(~any(isnan(A4),2),:);
B5=A5(~any(isnan(A5),2),:);datelabel5=datelabel(~any(isnan(A5),2),:);
clear datelabel X Y A*

% period definition
period1=(1:1:(length(datelabel1)))';
period2=(1:1:(length(datelabel2)))';
period3=(1:1:(length(datelabel3)))';
period4=(1:1:(length(datelabel4)))';
period5=(1:1:(length(datelabel5)))';

% ticks
ticks1=230:690:length(period1);
ticks2=130:380:length(period2);
ticks3=130:370:length(period3);
ticks4=190:480:length(period4);
ticks5=320:850:length(period5);

% figure creation
close all
figure('units','pixels','Position',[50,100,1500,300]);
s1=subplot(1,5,1);
wtc([period1 B1(:,1)],[period1 B1(:,2)],'maxscale',800)
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['SVI diff ("' cname ' ' cell2mat(names(1)) '")']});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=datelabel1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);

s2=subplot(1,5,2);
wtc([period2 B2(:,1)],[period2 B2(:,2)],'maxscale',800)
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(2)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wtc([period3 B3(:,1)],[period3 B3(:,2)],'maxscale',800)
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(3)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wtc([period4 B4(:,1)],[period4 B4(:,2)],'maxscale',800)
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(4)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wtc([period5 B5(:,1)],[period5 B5(:,2)],'maxscale',800)
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['SVI diff ("' cname ' ' cell2mat(names(5)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'fig03c','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'fig03c','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% Figure A03a - coherency: ASVI vs. returns - bitcoin
close all
clear
clc
cd('... path ...')
load('data02.mat')
% transformation and variable definition
n=size(btc,2)/3;
m=length(btc_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(btc{:,j},1);
    names(:,i)=btcnames(:,j);
    j=j+3;
end
datelabel=btc_datelabel(2:end,:);
Y(:,1)=g_btc_bitfinex;
Y(:,2)=g_btc_bitstamp;
Y(:,3)=g_btc_bittrex;
Y(:,4)=g_btc_coinbase;
Y(:,5)=g_btc_kraken;
Y=Y(2:end,:)-movmedian(Y(2:end,:),[6 0],1);
clearvars -except X Y datelabel names 
cname='bitcoin';
Cname='Bitcoin';

% NaN values
A1=[Y(:,1) X(:,1)];
A2=[Y(:,2) X(:,2)];
A3=[Y(:,3) X(:,3)];
A4=[Y(:,4) X(:,4)];
A5=[Y(:,5) X(:,5)];
B1=A1(~any(isnan(A1),2),:);datelabel1=datelabel(~any(isnan(A1),2),:);
B2=A2(~any(isnan(A2),2),:);datelabel2=datelabel(~any(isnan(A2),2),:);
B3=A3(~any(isnan(A3),2),:);datelabel3=datelabel(~any(isnan(A3),2),:);
B4=A4(~any(isnan(A4),2),:);datelabel4=datelabel(~any(isnan(A4),2),:);
B5=A5(~any(isnan(A5),2),:);datelabel5=datelabel(~any(isnan(A5),2),:);
clear datelabel X Y A*

% period definition
period1=(1:1:(length(datelabel1)))';
period2=(1:1:(length(datelabel2)))';
period3=(1:1:(length(datelabel3)))';
period4=(1:1:(length(datelabel4)))';
period5=(1:1:(length(datelabel5)))';

% ticks
ticks1=250:700:length(period1);
ticks2=250:720:length(period2);
ticks3=200:590:length(period3);
ticks4=270:710:length(period4);
ticks5=310:890:length(period5);

% figure creation
close all
figure('units','pixels','Position',[50,100,1500,300]);
s1=subplot(1,5,1);
wtc([period1 B1(:,1)],[period1 B1(:,2)],'maxscale',800)
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['ASVI ("' cname ' ' cell2mat(names(1)) '")']});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=datelabel1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);

s2=subplot(1,5,2);
wtc([period2 B2(:,1)],[period2 B2(:,2)],'maxscale',800)
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(2)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wtc([period3 B3(:,1)],[period3 B3(:,2)],'maxscale',800)
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(3)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wtc([period4 B4(:,1)],[period4 B4(:,2)],'maxscale',800)
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(4)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wtc([period5 B5(:,1)],[period5 B5(:,2)],'maxscale',800)
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(5)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'figA01a','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'figA01a','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% Figure A03b - coherency: ASVI vs. returns - ethereum
close all
clear
clc
cd('... path ...')
load('data02.mat')
% transformation and variable definition
n=size(eth,2)/3;
m=length(eth_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(eth{:,j},1);
    names(:,i)=ethnames(:,j);
    j=j+3;
end
datelabel=eth_datelabel(2:end,:);
Y(:,1)=g_eth_bitfinex;
Y(:,2)=g_eth_bitstamp;
Y(:,3)=g_eth_bittrex;
Y(:,4)=g_eth_coinbase;
Y(:,5)=g_eth_kraken;
Y=Y(2:end,:)-movmedian(Y(2:end,:),[6 0],1);
clearvars -except X Y datelabel names 
cname='ethereum';
Cname='Ethereum';

% NaN values
A1=[Y(:,1) X(:,1)];
A2=[Y(:,2) X(:,2)];
A3=[Y(:,3) X(:,3)];
A4=[Y(:,4) X(:,4)];
A5=[Y(:,5) X(:,5)];
B1=A1(~any(isnan(A1),2),:);datelabel1=datelabel(~any(isnan(A1),2),:);
B2=A2(~any(isnan(A2),2),:);datelabel2=datelabel(~any(isnan(A2),2),:);
B3=A3(~any(isnan(A3),2),:);datelabel3=datelabel(~any(isnan(A3),2),:);
B4=A4(~any(isnan(A4),2),:);datelabel4=datelabel(~any(isnan(A4),2),:);
B5=A5(~any(isnan(A5),2),:);datelabel5=datelabel(~any(isnan(A5),2),:);
clear datelabel X Y A*

% period definition
period1=(1:1:(length(datelabel1)))';
period2=(1:1:(length(datelabel2)))';
period3=(1:1:(length(datelabel3)))';
period4=(1:1:(length(datelabel4)))';
period5=(1:1:(length(datelabel5)))';

% ticks
ticks1=200:520:length(period1);
ticks2=120:320:length(period2);
ticks3=150:390:length(period3);
ticks4=200:500:length(period4);
ticks5=250:610:length(period5);

% figure creation
close all
figure('units','pixels','Position',[50,100,1500,300]);
s1=subplot(1,5,1);
wtc([period1 B1(:,1)],[period1 B1(:,2)],'maxscale',800)
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['ASVI ("' cname ' ' cell2mat(names(1)) '")']});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=datelabel1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);

s2=subplot(1,5,2);
wtc([period2 B2(:,1)],[period2 B2(:,2)],'maxscale',800)
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(2)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wtc([period3 B3(:,1)],[period3 B3(:,2)],'maxscale',800)
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(3)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wtc([period4 B4(:,1)],[period4 B4(:,2)],'maxscale',800)
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(4)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wtc([period5 B5(:,1)],[period5 B5(:,2)],'maxscale',800)
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(5)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'figA01b','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'figA01b','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);

%% Figure A03c - coherency: ASVI vs. returns - litecoin
close all
clear
clc
cd('... path ...')
load('data02.mat')
% transformation and variable definition
n=size(ltc,2)/3;
m=length(ltc_datelabel)-1;
X=NaN(m,n);
j=1;
for i=1:1:n
    X(:,i)=diff(ltc{:,j},1);
    names(:,i)=ltcnames(:,j);
    j=j+3;
end
datelabel=ltc_datelabel(2:end,:);
Y(:,1)=g_ltc_bitfinex;
Y(:,2)=g_ltc_bitstamp;
Y(:,3)=g_ltc_bittrex;
Y(:,4)=g_ltc_coinbase;
Y(:,5)=g_ltc_kraken;
Y=Y(2:end,:)-movmedian(Y(2:end,:),[6 0],1);
clearvars -except X Y datelabel names 
cname='litecoin';
Cname='Litecoin';

% NaN values
A1=[Y(:,1) X(:,1)];
A2=[Y(:,2) X(:,2)];
A3=[Y(:,3) X(:,3)];
A4=[Y(:,4) X(:,4)];
A5=[Y(:,5) X(:,5)];
B1=A1(~any(isnan(A1),2),:);datelabel1=datelabel(~any(isnan(A1),2),:);
B2=A2(~any(isnan(A2),2),:);datelabel2=datelabel(~any(isnan(A2),2),:);
B3=A3(~any(isnan(A3),2),:);datelabel3=datelabel(~any(isnan(A3),2),:);
B4=A4(~any(isnan(A4),2),:);datelabel4=datelabel(~any(isnan(A4),2),:);
B5=A5(~any(isnan(A5),2),:);datelabel5=datelabel(~any(isnan(A5),2),:);
clear datelabel X Y A*

% period definition
period1=(1:1:(length(datelabel1)))';
period2=(1:1:(length(datelabel2)))';
period3=(1:1:(length(datelabel3)))';
period4=(1:1:(length(datelabel4)))';
period5=(1:1:(length(datelabel5)))';

% ticks
ticks1=230:690:length(period1);
ticks2=130:380:length(period2);
ticks3=130:370:length(period3);
ticks4=190:480:length(period4);
ticks5=320:850:length(period5);

% figure creation
close all
figure('units','pixels','Position',[50,100,1500,300]);
s1=subplot(1,5,1);
wtc([period1 B1(:,1)],[period1 B1(:,2)],'maxscale',800)
colorbar('off');
s=get(s1, 'position');s(1)=0.04;s(3)=0.16;set(s1,'position',s); % [left bottom width height]
title({['ASVI ("' cname ' ' cell2mat(names(1)) '")']});
ylabel('Period (days)');
cmap=colormap(jet);
ticklabels=datelabel1(ticks1);set(gca,'XTick',ticks1);set(gca,'XTickLabel',ticklabels);

s2=subplot(1,5,2);
wtc([period2 B2(:,1)],[period2 B2(:,2)],'maxscale',800)
colorbar('off');
s=get(s2, 'position');s(1)=0.225;s(3)=0.16;set(s2,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(2)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel2(ticks2);set(gca,'XTick',ticks2);set(gca,'XTickLabel',ticklabels);

s3=subplot(1,5,3);
wtc([period3 B3(:,1)],[period3 B3(:,2)],'maxscale',800)
colorbar('off');
s=get(s3, 'position');s(1)=0.41;s(3)=0.16;set(s3,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(3)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel3(ticks3);set(gca,'XTick',ticks3);set(gca,'XTickLabel',ticklabels);

s4=subplot(1,5,4);
wtc([period4 B4(:,1)],[period4 B4(:,2)],'maxscale',800)
colorbar('off');
s=get(s4, 'position');s(1)=0.595;s(3)=0.16;set(s4,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(4)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel4(ticks4);set(gca,'XTick',ticks4);set(gca,'XTickLabel',ticklabels);

s5=subplot(1,5,5);
wtc([period5 B5(:,1)],[period5 B5(:,2)],'maxscale',800)
s=get(s5, 'position');s(1)=0.78;s(3)=0.16;set(s5,'position',s);
title({['ASVI ("' cname ' ' cell2mat(names(5)) '")']});
ylabel(' ');
cmap=colormap(jet);
ticklabels=datelabel5(ticks5);set(gca,'XTick',ticks5);set(gca,'XTickLabel',ticklabels);

mkdir('results_final');
cd('results_final');
%saveas(gcf,'figA01c','png');
h=gcf;
set(h,'PaperOrientation','landscape');
print(gcf,'figA01c','-dpdf','-bestfit','-r600');
cd('..');
close(gcf);


